function getCurrentDate() {
  const myDate = new Date();
  let year = myDate.getFullYear();
  let month = myDate.getMonth() + 1;
  let day = myDate.getDate();
  if (month < 10) month = `0${month}`;
  if (day < 10) day = `0${day}`;
  return [year, month, day].join('-');
}

function getMonthDays(year, month) {
  let d = new Date(year, month, 0);
  return d.getDate();
}

function getCurrentTime() {
  const myDate = new Date();
  let min = myDate.getMinutes();
  if (parseInt(min) < 10) {
    min = `0${min}`;
  }

  let hour = myDate.getHours();
  if (parseInt(hour) < 10) {
    hour = `0${hour}`;
  }

  let second = myDate.getSeconds();
  if (parseInt(second) < 10) {
    second = `0${second}`;
  }
  return [hour, min, second].join(':');
}

function arrayIsNull(array) {
  return array === undefined || null === array || array === [] || array.length === 0;
}

function isNull(obj) {
  return obj === undefined || null === obj || obj === [] || obj === '';
}

async function getImageInfo(src) {
  return new Promise(function(resolve) {
    wx.getImageInfo({
      src: src,
      success: function(res) {
        resolve(res);
      },
      fail: function() {
        resolve();
      }
    });
  });
}

module.exports = {
  getCurrentDate,
  getCurrentTime,
  arrayIsNull,
  getImageInfo,
  isNull,
  getMonthDays
};
